/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.webhomesites.padrao.view;

import br.com.webhomesites.padrao.model.ClienteDAO;
import br.com.webhomesites.padrao.model.ClienteModel;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.util.List;
import javax.swing.JTextField;

/**
 *
 * @author Webhome
 */
public class RelLocPorCLiView extends javax.swing.JDialog {

    /**
     * Creates new form DevolucaoTotComPagView
     */
    public RelLocPorCLiView(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();     
        ClienteDAO clienteDAO = new ClienteDAO();
        this.setComboNomeCliente(clienteDAO.findAll());
        
        setLocationRelativeTo(null);
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelCentralProduto = new javax.swing.JPanel();
        labelDataFinal = new javax.swing.JLabel();
        txtDataFinal = new javax.swing.JTextField();
        labelDataInicial = new javax.swing.JLabel();
        txtDataInicial = new javax.swing.JTextField();
        comboClienteNome = new javax.swing.JComboBox();
        labelClienteNome = new javax.swing.JLabel();
        btnCancelar = new javax.swing.JButton();
        btnPesquisar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        painelCentralProduto.setBorder(javax.swing.BorderFactory.createTitledBorder("Locações por Cliente"));

        labelDataFinal.setText("até");

        labelDataInicial.setText("Data de:");

        labelClienteNome.setText("Nome do Cliente");

        javax.swing.GroupLayout painelCentralProdutoLayout = new javax.swing.GroupLayout(painelCentralProduto);
        painelCentralProduto.setLayout(painelCentralProdutoLayout);
        painelCentralProdutoLayout.setHorizontalGroup(
            painelCentralProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelCentralProdutoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelCentralProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelCentralProdutoLayout.createSequentialGroup()
                        .addGroup(painelCentralProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(painelCentralProdutoLayout.createSequentialGroup()
                                .addGroup(painelCentralProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelDataInicial)
                                    .addComponent(txtDataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(painelCentralProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelDataFinal)
                                    .addComponent(txtDataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(labelClienteNome))
                        .addGap(0, 251, Short.MAX_VALUE))
                    .addComponent(comboClienteNome, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        painelCentralProdutoLayout.setVerticalGroup(
            painelCentralProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelCentralProdutoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelCentralProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelDataInicial)
                    .addComponent(labelDataFinal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelCentralProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDataFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDataInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labelClienteNome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboClienteNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/block-icon.png"))); // NOI18N
        btnCancelar.setMnemonic('c');

        btnPesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/search-icon.png"))); // NOI18N
        btnPesquisar.setMnemonic('p');

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(painelCentralProduto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(painelCentralProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnPesquisar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(RelLocPorCLiView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(RelLocPorCLiView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(RelLocPorCLiView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(RelLocPorCLiView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                RelLocPorCLiView dialog = new RelLocPorCLiView(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JComboBox comboClienteNome;
    private javax.swing.JLabel labelClienteNome;
    private javax.swing.JLabel labelDataFinal;
    private javax.swing.JLabel labelDataInicial;
    private javax.swing.JPanel painelCentralProduto;
    private javax.swing.JTextField txtDataFinal;
    private javax.swing.JTextField txtDataInicial;
    // End of variables declaration//GEN-END:variables
  
    public void packAndShow() {
        
        this.pack();
        this.setVisible(true);
    }
    
   public void setDataInicial(String dataInicial) {
        this.txtDataInicial.setText(dataInicial);
    }
    
    public String getDataInicial() {
        return txtDataInicial.getText();
    }
    
    public void setDataFinal(String dataFinal) {
        this.txtDataFinal.setText(dataFinal);
    }
    
    public String getDataFinal() {
        return txtDataFinal.getText();
    }
    
    public void setNomeCliente(String nomeCliente) {
        this.comboClienteNome.setSelectedItem(nomeCliente);
    }
    
    public String getNomeCliente() {
        return comboClienteNome.getSelectedItem().toString();
    }   
    
    public void setComboNomeCliente(List<ClienteModel> listaClientes) {
        comboClienteNome.removeAllItems();
        for (int i = 0; i < listaClientes.size(); i++) // Percorro o Array List com o For aprimorado.  
        {
            this.comboClienteNome.addItem(listaClientes.get(i).getNome()); // Adiciono os dados.  
        }
    }
 
    public void clearFields() {
        Component[] componentes = this.painelCentralProduto.getComponents();  
          
        for (int i = 0; i < componentes.length; i++) {  
            if (componentes[i] instanceof JTextField) {  
                JTextField field = (JTextField)componentes[i];  
                field.setText("");  
            }  
        }  
    }
    
    public void setCampoKeyListener(KeyListener listener) {
        txtDataInicial.addKeyListener(listener);
        txtDataFinal.addKeyListener(listener);
    }
    
    public void enableBtnPesquisar(boolean arg) {
        this.btnPesquisar.setEnabled(arg);
    }
    
    public void enableBtnCancelar(boolean arg) {
        this.btnCancelar.setEnabled(arg);
    }
      
    public void setCancelarActionListener(ActionListener listener) {
        this.btnCancelar.addActionListener(listener); 
    }
    
    public void setBtnSairActionListener(ActionListener listener) {
        //this.btnSair.addActionListener(listener); 
    }
    
    public void setEmitirRelatorioActionlistener(ActionListener listener) {
        this.btnPesquisar.addActionListener(listener);
    } 
}

